package day12;

import cn.hutool.core.io.IoUtil;

import java.io.*;
import java.util.ArrayList;
import java.util.Random;

import static day12.homework02.insertnames;

public class homework04 {
    public static void main(String[] args) throws Exception {
        BufferedReader reader1= IoUtil.getReader(new FileReader("womannames.txt"));
        BufferedReader reader2=IoUtil.getReader(new FileReader("mannames.txt"));
        ArrayList<String> names=insertnames(reader1,reader2);
        reader2.close();
        reader1.close();
        int sum=0;
        count();
        named(names,sum);

    }

    private static void named(ArrayList<String> names, int sum) {
        try {
            BufferedReader reader = IoUtil.getReader(new FileReader("work04num.txt"));
            int a;
            while((a=reader.read())!= -1){
                sum+=a;
            }
            reader.close();
            if(sum%3==0){
                System.out.println("张三-男-24");
            }else{
                Random rm=new Random();
                int numbering=rm.nextInt(names.size());
                System.out.println(names.get(numbering));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void count() {
        int nums=1;
        try {
            BufferedWriter bw=new BufferedWriter(new FileWriter("work04num.txt",true));
            bw.write(nums);
            bw.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
